﻿Imports System.Text
Imports ThoughtWorks.CruiseControl.Core
Imports ModificationMonitor

<TestClass(), CLSCompliant(False)>
Public Class ModificationMonitorTest
  Inherits ModificationMonitor.ModificationMonitor

  Private testContextInstance As TestContext

  '''<summary>
  '''Ruft den Textkontext mit Informationen über
  '''den aktuellen Testlauf sowie Funktionalität für diesen auf oder legt diese fest.
  '''</summary>
  Public Property TestContext() As TestContext
    Get
      Return testContextInstance
    End Get
    Set(ByVal value As TestContext)
      testContextInstance = value
    End Set
  End Property

#Region "Zusätzliche Testattribute"
  '
  ' Sie können beim Schreiben der Tests folgende zusätzliche Attribute verwenden:
  '
  ' Verwenden Sie ClassInitialize, um vor Ausführung des ersten Tests in der Klasse Code auszuführen.
  ' <ClassInitialize()> Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
  ' End Sub
  '
  ' Verwenden Sie ClassCleanup, um nach Ausführung aller Tests in einer Klasse Code auszuführen.
  ' <ClassCleanup()> Public Shared Sub MyClassCleanup()
  ' End Sub
  '
  ' Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen.
  ' <TestInitialize()> Public Sub MyTestInitialize()
  ' End Sub
  '
  ' Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen.
  ' <TestCleanup()> Public Sub MyTestCleanup()
  ' End Sub
  '
#End Region

  '/////////////////////////////////////////////////////////////////////////
#Region "SqlStatementTest"

  <TestMethod()>
  Public Sub SqlStatementTest()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.SqlStatement = "SELECT GETDATE()"
    Assert.AreEqual("SELECT GETDATE()", target.SqlStatement)
    target.SqlStatement = "8"
    Assert.AreEqual("8", target.SqlStatement)
    target.SqlStatement = Nothing
    Assert.IsNull(target.SqlStatement)
  End Sub

#End Region

  '/////////////////////////////////////////////////////////////////////////
#Region "TimeoutTest"

  <TestMethod()>
  Public Sub TimeoutTest()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.Timeout = 5
    Assert.AreEqual(5, target.Timeout)
    target.Timeout = 0
    Assert.AreEqual(0, target.Timeout)
    target.Timeout = -6
    Assert.AreEqual(-6, target.Timeout)
    target.Timeout = Integer.MaxValue
    Assert.AreEqual(Integer.MaxValue, target.Timeout)
    target.Timeout = Integer.MinValue
    Assert.AreEqual(Integer.MinValue, target.Timeout)
  End Sub

#End Region

  '/////////////////////////////////////////////////////////////////////////
#Region "ConnectionStringTest"

  <TestMethod()>
  Public Sub ConnectionStringTest()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.ConnectionString = "Provider=SQLNCLI11.1;Integrated Security=SSPI;Persist Security Info=False;User ID="";Initial Catalog="";Data Source=CLVDOPMA01;Initial File Name="";Server SPN="""
    Assert.AreEqual("Provider=SQLNCLI11.1;Integrated Security=SSPI;Persist Security Info=False;User ID="";Initial Catalog="";Data Source=CLVDOPMA01;Initial File Name="";Server SPN=""", target.ConnectionString)
    target.ConnectionString = "ich funktioniere nicht"
    Assert.AreEqual("ich funktioniere nicht", target.ConnectionString)
    target.ConnectionString = "8"
    Assert.AreEqual("8", target.ConnectionString)
    target.ConnectionString = Nothing
    Assert.IsNull(target.ConnectionString)
    target.ConnectionString = ""
    Assert.AreEqual("", target.ConnectionString)
  End Sub

#End Region

  '/////////////////////////////////////////////////////////////////////////
#Region "GetModificationsTest"

  <TestMethod(), ExpectedException(GetType(ArgumentNullException))>
  Public Sub GetModificationsTest1()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.GetModifications(Nothing, New IntegrationResult())
  End Sub

  <TestMethod(), ExpectedException(GetType(ArgumentNullException))>
  Public Sub GetModificationsTest2()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.GetModifications(New IntegrationResult(), Nothing)
  End Sub

  <TestMethod(), ExpectedException(GetType(ConfigurationException))>
  Public Sub GetModificationsTest3()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.GetModifications(New IntegrationResult(), New IntegrationResult())
  End Sub

#End Region

  '/////////////////////////////////////////////////////////////////////////
#Region "GetFormatedDateTest"
  <TestMethod()>
  Public Sub GetFormatedDateTest()
    Dim [date] As New Date(2008, 1, 3, 13, 0, 0)
    Assert.AreEqual("2008-01-03 13:00:00", GetFormatedDate([date]))
  End Sub
#End Region

  '/////////////////////////////////////////////////////////////////////////
#Region "ConfigurationException"
  <TestMethod(), ExpectedException(GetType(ConfigurationException))>
  Public Sub ExceptionTest1()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.ConnectionString = "" '<--- to check
    target.SqlStatement = "SELECT * FROM table"
    target.Timeout = 5
    target.GetModifications(New IntegrationResult(), New IntegrationResult())
  End Sub

  <TestMethod(), ExpectedException(GetType(ConfigurationException))>
  Public Sub ExceptionTest2()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=myDataBase;Data Source=localhost"
    target.SqlStatement = "" '<--- to check
    target.Timeout = 5
    target.GetModifications(New IntegrationResult(), New IntegrationResult())
  End Sub

  <TestMethod(), ExpectedException(GetType(ConfigurationException))>
  Public Sub ExceptionTest3()
    Dim target As New ModificationMonitor.ModificationMonitor()
    target.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=myDataBase;Data Source=localhost"
    target.SqlStatement = "SELECT * FROM table"
    target.Timeout = -5 '<--- to check
    target.GetModifications(New IntegrationResult(), New IntegrationResult())
  End Sub
#End Region

End Class
